

import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;


public class KW {
	
	public static void enterText(FirefoxDriver driver, String xPath, String Data) {
		// Purpose: Enter text into a edit field
		//i/p: driver, xPath, Data
		//o/p:  Nil
		//CreatedBy : Priya
		//When :8/05/14
		//EditedBy : Priya
		//When : 8/5/14
		
		driver.findElement(By.xpath(xPath)).clear();//some applications already have a default values in edit field, so this line is to clear the default path
		driver.findElement(By.xpath(xPath)).sendKeys(Data);
		
	}
	

	
	
	public static String readText(FirefoxDriver driver, String xPath) {  //B'coz im going to get an o/p, I changed void to String to return the data
		// Purpose: read text from any field.
		//i/p: driver, xPath
		//o/p:  Data
		//CreatedBy : Priya
		//When :8/05/14
		//EditedBy : Priya
		//When : 8/5/14
		
		return driver.findElement(By.xpath(xPath)).getText(); //returns whatever comes here
	}
	
	public static String verifyText(FirefoxDriver driver, String xPath, String vText) {  //B'coz im going to get an o/p, I changed void to String to return the data
		// Purpose: verifies text from any field.
		//i/p: driver, xPath
		//o/p:  Data
		//CreatedBy : Priya
		//When :8/05/14
		//EditedBy : Priya
		//When : 8/5/14
		
		if (vText.equalsIgnoreCase(driver.findElement(By.xpath(xPath)).getText())){  //returns whatever comes here
			
			return "pass"; 
			
		} else {
			return "Fail";
		}
		
		
	}
	

	
	
	public static void clickElement(FirefoxDriver driver, String xPath) {  //B'coz im going to get an o/p, I changed void to String to return the data
		// Purpose: Click any element on the AUT
		//i/p: driver, xPath
		//o/p:  NIl
		//CreatedBy : Priya
		//When :8/05/14
		//EditedBy : Priya
		//When : 8/5/14
		
		driver.findElement(By.xpath(xPath)).click(); // sometimes click may not work, so I write a code to send enter
		//driver.findElement(By.linkText(linkText)).click();
		//driver.findElement(By.xpath(xPath)).sendKeys("\n");
		
	}
		
	public static void clickElementbylink(FirefoxDriver driver, String link) {  //B'coz im going to get an o/p, I changed void to String to return the data
		// Purpose: Click any element on the AUT
		//i/p: driver, xPath
		//o/p:  NIl
		//CreatedBy : Priya
		//When :8/05/14
		//EditedBy : Priya
		//When : 8/5/14
		
		driver.findElement(By.linkText(link)).click();
		driver.findElement(By.linkText(link)).sendKeys("\n");
		
	}
		
	
		public static void selectList(FirefoxDriver driver, String xPath, String Data) { 
			// Purpose: Select from a drop down list 
			//i/p: driver, xPath, Data
			//o/p:  NIl
			//CreatedBy : Priya
			//When :8/05/14
			//EditedBy : Priya
			//When : 8/5/14
			
		Select myList = new Select(driver.findElement(By.xpath(xPath)));//creating memory in myList
		myList.selectByVisibleText(Data);
		myList = null;  //clears the memory in my list
			
		}
			
			
	
		public static void checkBox(FirefoxDriver driver, String xPath) {  //this has to be checked.
			// Purpose: checks a checkbox
			//i/p: driver, xPath
			//o/p:  NIl
			//CreatedBy : Priya
			//When :8/05/14
			//EditedBy : Priya
			//When : 8/5/14
			
		//Is it checked?
			if(driver.findElement(By.xpath(xPath)).getAttribute("checked").equalsIgnoreCase("checked")){
				//then do nothing
		
			} else {
			//click
			driver.findElement(By.xpath(xPath)).click();
			}		
		}

	//uncheckBox
	// selectRadio
	
	public static void navigateBrowser(FirefoxDriver driver, String Data){
		// Purpose: Navigates a browser to a URL
					//i/p: driver, xPath
					//o/p:  NIl
					//CreatedBy : Priya
					//When :8/05/14
					//EditedBy : Priya
					//When : 8/5/14
		
		driver.navigate().to(Data);
		
	}

	public static void waitTime(long lTime) throws Exception{
		// Purpose: it will wait for a certain amount of time.
					//i/p: time in milli seconds
					//o/p:  NIl
					//CreatedBy : Priya
					//When :8/05/14
					//EditedBy : Priya
					//When : 8/5/14
		
		Thread.sleep(lTime);
		
	}
	
}

